package com.example.myapplication.routertest

import androidx.navigation.NavType
import androidx.navigation.navArgument
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
@SerialName("home")
object HomeRoute

@Serializable
@SerialName("page1")
object Page1Route

@Serializable
@SerialName("page2")
object Page2Route

@Serializable
@SerialName("dialog1")
object Dialog1Route

@Serializable
@SerialName("detail")
object DetailRoute {
    @Serializable
    @SerialName("detail1")
    object Detail1Route
}

// 官方不支持直接将user/{id}用安全路由的形式书写
// 此处用密封类进行手动封装
sealed class SafeRoute(val route: String) {
    data object User: SafeRoute("user/{id}") {
        const val ID = "id"
        fun path(id: Int) = "user/$id"
        fun args() = listOf(
            navArgument(ID) {
                type = NavType.IntType  // 强制类型声明
            }
        )
    }
}

@Serializable
@SerialName("student") // 默认会转换为student?stuName={stuName}
data class StudentRoute(val stuName: String)